package org.mybatis.practice;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import po.Department;

import javax.annotation.Resource;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;


public class Test {
    public static void main(String[] args) throws IOException {
        String resource = "mybatis_config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactoryBuilder  sqlSessionFactoryBuilder= new SqlSessionFactoryBuilder();
        SqlSessionFactory sqlSessionFactory = sqlSessionFactoryBuilder.build(inputStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();

        Department dp = new Department();
        dp.setDepart_posts("测试");

        List<Department> list = sqlSession.selectList("department.selectall",dp);
        for (Department department : list){
            System.out.println(department.getDepart_posts()+"-"+department.getDepart_people()+"-"+department.getPeople().getSex());
        }

    }
}
